package com.woniuxy.movie.system.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.movie.system.dao.SystemAccountMapper;
import com.woniuxy.movie.system.dto.AccountDto;
import com.woniuxy.movie.system.exception.SystemException;
import com.woniuxy.movie.system.form.AccountLoginForm;
import com.woniuxy.movie.system.model.SystemAccount;
import com.woniuxy.movie.system.service.SystemAccountService;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author XIAO
 * @since 2023年10月10日
 */
@Service
public class SystemAccountServiceImpl extends ServiceImpl<SystemAccountMapper, SystemAccount> implements SystemAccountService {

    @Override
    public AccountDto login(AccountLoginForm form) {
        SystemAccount account = getOne(new LambdaQueryWrapper<SystemAccount>().eq(SystemAccount::getAccountName, form.getAccountName()));
        if (account == null) throw new SystemException(1001,"账号不存在");
        if (account.getAccountState() != 1) throw new SystemException(1001,"账号状态异常");
        if (!account.getAccountPass().equals(form.getAccountPass())) throw new SystemException(1001,"密码错误");
        return BeanUtil.toBean(account,AccountDto.class);
    }
}
